# Code for [*Optimal Fiscal Policy With Heterogeneous Agents and Capital:Should We Increase or Decrease Public Debt and Capital Taxes?*](https://xavier-ragot.fr/pdf/progress/LeGrand_Ragot_debt.pdf)
# Authors: François Le Grand and  Xavier Ragot

## Introduction

We  explain how to run the replication files.

- We first use **Julia** (Version 1.7) to solve for the steady state equilibrium and compute the relevant Lagrange multipliers.

- We use a finite state-space representation for the dynamics and use the **Dynare** solver, which requires **Matlab** (Version 9.4.0.81365, R2018a). 

## The steady state

1. The main file is the notebook [**Main.ipynb**](./Main.ipynb). It calls external functions and allows the computation of the Ramsey steady-state solution for a given calibration. This is the only notebook that actually needs to be run.
2. The notebook is commented and self-explained. All cells can be run.
3. The main output is the file [`ToDynare.mat`], which is used as input in all dynamic simulations.
4. A secondary output is the file [`ToDynare_Reiter.mat`], which is used for the comparison with the Reiter's method.


## Dynamics

We compute the model dynamics for three shocks. We also compare the truncation method to the Reiter one.

1. Public spending shock: the files are in the folder [`/simulation_opti_G/`].
2. TFP shock: the files are in the folder [`/simulation_opti_Z/`].
3. Discount factor shock: the files are in the folder [`/simulation_opti_beta/`].
4. The comparison with Reiter is in the folder [`/Comparison_trunc_Reiter/`].



### Public spending shock
We detail the case of the  public spending shocks, the other cases are similar.

All files are located in the folder [`/simulation_opti_G/`].

1. The main file is [**/simulation_opti_G/write_dynare_opti.m**](./simulation_opti_G/write_dynare_opti.m), which simulates the dynamics of the Ramsey solution in the heterogeneous-agent economy.

    a. It simulates the optimal dynamics  for a value of the shock persistence  of [`rho_u=0.1`] (for instance). This is a Matlab file that writes and launches a Dynare file. 

    b. The value of [`rho_u`] can be changed at the beginning of the file.

    c. It saves the results in the file [`fig_opti0.1.mat`] (if rho_u=0.1).


2. A  second file is [**/simulation_opti_G/write_dynare_FB.m**](./simulation_opti_G/write_dynare_FB.m) simulates the dynamics of the Ramsey solution in the corresponding  representative-agent economy. The three steps are the same as in the heterogeneous-agent economy.  The results are saved in a file [`fig_opti0.1FB.mat`] (if rho_u=0.1).

3. The three figures of the papers are plotted using the following files.

    a. The file [**/simulation_opti_G/do_figure_opti.m**](./simulation_opti_G/do_figure_opti.m) plots the IRFs for the HA case. This is  Figure 1 in the paper.

    b. The file [**/simulation_opti_G/do_figure_opti_FB.m**](./simulation_opti_G/do_figure_opti_FB.m) plots the IRFs for the HA case together with the first-best case. This is Figure 2 in the paper.

    c. The file [**/simulation_opti_G/do_figure_debt_multi.m**](./simulation_opti_G/do_debt_multi.m) plots the IRFs for public debt for the HA case, for different values of the persistence of the shock. This is the Figure 3 in the paper.

### Other shocks

The files in the two other folders (for the two other shocks) are the same and have the same names. 
